/**
 * 企业 合作伙伴 
 */
module.exports = class extends baseController{
    constructor(){
        super();
        this.partnersLogic=this.loadLogic('iframe/partners');
        this.router.post('/getItems',this.getItems.bind(this));
        this.router.post('/getItem',this.getItem.bind(this));
        this.router.post('/edit',this.edit.bind(this));
        this.router.post('/del',this.del.bind(this));
        this.router.post('/getAllItems',this.getAllItems.bind(this));
        return this.router;
    }

    static init(){
        return new this();
    }

    async getItems(req,res){
       let Result={};
        try{
            let CurPage = req.body.CurPage ? Number(req.body.CurPage) : 1;
            let PageSize = req.body.PageSize ? Number(req.body.PageSize) : 20;
            let Sort = req.body.Sort ? req.body.Sort : "OS_CreateTime|desc";
            let FindFilterModel={};
            FindFilterModel.OS_Name = req.body.OS_Name;
            FindFilterModel.OS_PlatformRuleID = Number("0" + req.body.OS_PlatformRuleID);
            FindFilterModel.OS_PlatFormID = Number("0" + req.body.OS_PlatFormID);
            FindFilterModel.OS_CreateTime = req.body.OS_CreateTime;
            let ret=await this.partnersLogic.getItems(FindFilterModel,CurPage,PageSize,Sort,req.user);
            Result=this.Success(1,ret);
        }catch(err){
            Result=this.Error('数据查询失败',err);
        }
        res.json(Result);
    }

    async getItem(req,res){
        let Result={};
        let ret={};
        try{
            let id = Number("0" + req.body.id);
            ret =await this.partnersLogic.getItem(id);
            if(!ret.Model){
                return res.json(this.Error('记录不存在'));
            }
            
            Result=this.Success(1,ret);
        }catch(err){
            Result=this.Error('数据查询失败',err);
        }
        res.json(Result);
    }

    async edit(req,res){
        let Result={};
        try{
            let ret=this.partnersLogic.insertOrUpdate(req.body);
            if(ret){
                Result=this.Success(1,ret);
            }else{
                Result=this.Error("数据保存失败");
            }
          
        }catch(err){
            Result=this.Error('数据保存失败',err);
        }
        res.json(Result);
    }

    async del(req,res){
        let Result={};
        try{
            let keys = req.body.keys;
            let ret=this.partnersLogic.del(keys);
            Result=this.Success(1,ret);
        }catch(err){
            Result=this.Error('数据查询失败',err);
        }
        res.json(Result);
    }



    async getAllItems(req,res){
        let Result={};
        try{
            let ret= await this.partnersLogic.getAllItems();
            Result=this.Success(1,ret);
        }catch(err){
            Result=this.Error('数据查询失败',err);
        }
        res.json(Result);
    } 

    
};









